package com;

import java.io.IOException;


import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns = "/test" ,asyncSupported=true)
public class Tsts extends HttpServlet {
	
	public Tsts() {
		super();
	}
	public void destroy() {
		super.destroy(); 
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		try {
			final String msg = request.getParameter("msg");
			final AsyncContext asyn = request.startAsync();
			final HttpServletResponse resp = response;
			asyn.setTimeout(8000);
			Runnable run = new Runnable() {
				
				@Override
				public void run() {
					
					System.out.println("asyn job start ....");
					try {
						resp.getWriter().print("return mgs : " + msg);
						asyn.dispatch("/data.jsp");
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			};
			asyn.complete();
			
			asyn.start(run);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	}

	public void init() throws ServletException {
		
	}
	

}
